//
//  LanguageViewController.m
//  51-Tour
//
//  Created by xiang ying on 14-3-21.
//  Copyright (c) 2014年 xiang ying. All rights reserved.
//

#import "LanguageViewController.h"

@interface LanguageViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSArray *_itemsArray,*_imagesArray;
}


@end

@implementation LanguageViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initNavigationItme:[[DataCenter instance] getStringForKey:@"Language"]];
    
    _itemsArray = @[@"中文",@"English"];
    _imagesArray = @[@"radio-box-selected_17",@"radio-box_17"];
    
    UITableView *menu = [[UITableView alloc] initWithFrame:CGRectMake(10, 40, 320-20, 44*2)];
    menu.separatorStyle = UITableViewCellSeparatorStyleNone;
    [menu setBackgroundColor:[UIColor whiteColor]];
    menu.scrollEnabled = NO;
    menu.dataSource = self;
    menu.delegate = self;
    [self.contentView addSubview:menu];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - UITableViewDataSource & UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _itemsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.backgroundColor = [UIColor clearColor];
        
        UIImageView *_line = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"list-line_14"]];
        _line.frame = CGRectMake(0, 43, 320, 1);
        [cell addSubview:_line];
    }
    cell.textLabel.text = _itemsArray[indexPath.row];
    
    if ([[DataCenter instance] getLanguageType] == zh_cn) {
        cell.imageView.image = [UIImage imageNamed:_imagesArray[indexPath.row]];
    }else{
        cell.imageView.image = [UIImage imageNamed:_imagesArray[1-indexPath.row]];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:{
            if ([[DataCenter instance] getLanguageType] == en_us) {
                //中文
                [[DataCenter instance] setLanguangeType:zh_cn];
                [self popself];
            }
        }
            
            break;
            
        case 1:{
            if ([[DataCenter instance] getLanguageType] == zh_cn) {
                //英文
                [[DataCenter instance] setLanguangeType:en_us];
                [self popself];
            }
        }
            break;
            
        default:
            break;
    }
}

@end
